home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!txwang
- From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
- Newsgroups: comp.lang.c++
- Subject: Re: Inheritance problem...and other stuff
- Date: Sun, 24 Mar 1996 10:54:27 GMT
- Message-ID: <199603232309.HAA23168@public1.guangzhou.gd.cn>
- X-NNTP-Posting-Host: txwang
- X-Newsreader: Forte Free Agent 1.0.82
- X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
-
- On 23 Mar 1996 14:49:22 GMT, grantp@usa.pipeline.com(Pete Grant)
- wrote:
-
- | On Mar 23, 1996 09:01:07 in article <Inheritance problem...and other
- | stuff>, 'pcgpe@ix.netcom.com(Mark Feldman)' wrote:
- |
- | >2nd Question:
- | >
- | >What's the standard way of storing such an array to a file and
- | >retrieving it? I could always assign an ID number to each class type
- | >and load them using case statements but this seems messy. I notice that
- | >MFC and OWL seem to use tables to handle the dispatching of windows
- | >messages. Would it be feasable to use this for saving the array info to
- | >a file? Idealy I would like each function to inherit a serialization
- | >function which they can overload to save and restore their data, but
- | >how can I make the loading routine know what type of class to create in
- | >the first place while still keeping the code tight and clean?
- | >
- | There's only one way: store the type information in the file. An
- | enum is probably best; alternately, a name string would work also.
- | When you read the data back in, you must check the type info and
- | create an object of appropriate type.
- |
- | There are standard idioms (Coplien's book, for example) for simulating
- | virtual constructors -- I have mixed feelings of those since they
- | are just a thin veil for hiding what you are really doing. There's
- | really no such thing as a virtual constructor in C++ and I feel a bit
- | uneasy with idioms that try to make it look like they exist. But
- | at the same time, I can see the benefits also.
-
- In Borland C++, there is a Streamable Class hierarchy, which does what
- Mark wants and even more. Search TStreamable in the online help.
-
- ---
- Wang TianXing
-
-
-